#include <iostream>
#include <pthread.h>
#include <ctime>
#include <unistd.h>
typedef void (*_callback)();

class thread
{
public:
	static void* ThreadRoutine(void* args)
	{
		thread* td = static_cast<thread*>(args);
		
		td->entery();

		//pthread_exit(void*(666));
		return nullptr;
	}

public:
	thread(_callback cb):_cb(cb), tid(0), threadtime(0), isrunning(false)  
	{}
	 
	void Run()
	{
		isrunning = true;
		threadtime = time(nullptr);
		threadname = "thread-1";		
		pthread_create(&tid, nullptr, ThreadRoutine, this);
	}

	void join()
	{
		pthread_join(tid, nullptr);
	}

	bool IsRunning()
	{
		return isrunning;
	}
	
	pthread_t get_tid()
	{
		return tid;
	}		

	uint64_t ThreadTime()
	{
		return threadtime;
	}
	
	std::string ThreadName()
	{
		return threadname;
	}

	void entery()
	{
		_cb();
	}

	~thread()
	{}
	
private:
	//线程tid
	pthread_t tid;
	//线程启动时间
	uint64_t threadtime;
	//线程名称
	std::string threadname;
	//线程是否启动
	bool isrunning;
	
	//回调函数
	_callback _cb;
};

